package daniel.taotao.service.Impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import daniel.taotao.common.pojo.itemCatList;
import daniel.taotao.mapper.TbItemCatMapper;
import daniel.taotao.pojo.TbItemCat;
import daniel.taotao.pojo.TbItemCatExample;
import daniel.taotao.pojo.TbItemCatExample.Criteria;
import daniel.taotao.service.ItemCataService;
@Service
public class ItemCataServiceImpl implements ItemCataService{
	@Autowired
	TbItemCatMapper itemCatMapper;
	@Override
	public List<itemCatList> getItemCataList(Long id) {
		List<itemCatList> list=new ArrayList<>();
		TbItemCatExample example=new TbItemCatExample();
		Criteria criteria = example.createCriteria();
		criteria.andParentIdEqualTo(id);
		List<TbItemCat> list2 = itemCatMapper.selectByExample(example);
		for(TbItemCat cat:list2){
			itemCatList ic=new itemCatList();
			ic.setId(cat.getId());
			ic.setText(cat.getName());
			ic.setState(cat.getIsParent()?"closed":"open");
			list.add(ic);
		}
		return list;
	}

}
